<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://isofttime.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: $this <498944516@qq.com>
// +----------------------------------------------------------------------
namespace app\we\model;

use think\Model;



class WeSceneQrcode extends Model
{


    // 根据scene_id,scene_str 获取二维码信息
    public function info($appid,$scene_id, $field = true)
    {
        
        if (!$scene_id) return false;
        $map['appid'] = $appid;
        if (is_numeric($scene_id)){
            $map['scene_id'] = $scene_id;
        }else{
            $map['scene_str'] = $scene_id;
        }
        
        return $this->field($field)->where($map)->find();
    }

     // 获取自增scene_id;
    public function autoScene_id($appid,$type=0)
    {
        if (!$appid) return false;
        $map['appid']=$appid;
        $map['qrcode_type']=$type;
        $max=$this->where($map)->max('scene_id');
        if ($type==0 and !$max) $max=320000;  //避免与永久二维码冲突
        if ($type==1 and !$max) $max=0;
        $scene_id=intval($max)+1;
       
        return $scene_id;
    }

   

    // 保存消息记录
    public function saveSceneQrcode($data)
    {
       
        try{
            $result =  $this->allowField(true)->save($data);

        }catch( PDOException $e){
            $res=  ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
        $res=  ['code' => 1, 'data' => '', 'msg' => '添加消息成功'];
        return $res;
    }

     

   
   
}